package com.sx.pipeline.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.noober.background.view.BLImageView
import com.sx.mvvmlibs.base.EasyAdapter
import com.sx.pipeline.R
import com.sx.pipeline.repos.http.res.ContactUserVo

/**
 * author : zhouyouqiang
 * e-mail : 1638473898@qq.com
 * date   : 2022/4/11 15:59
 * desc   : 搜索联系人
 * version: 1.0
 */
class SearchContactAdapter(
    private val contexts: Context,
    private val type:Int?,
    private val serviceData: List<ContactUserVo>,
) : EasyAdapter<String,SearchContactViewHolder?>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchContactViewHolder {
        val view = View.inflate(contexts, R.layout.item_search_contact, null)
        return SearchContactViewHolder(view)
    }

    override fun getItemCount(): Int {
        return serviceData.size
    }

    override fun whenBindViewHolder(holder: SearchContactViewHolder?, position: Int) {
         val data = serviceData[position]
        holder!!.ivChecked.tag = position //绑定
        Glide.with(contexts).load(data.avatar).placeholder(R.mipmap.ic_default_head).into(holder.ivImg)
        holder.tvName.text=data.userName
        if (type==0){
            holder.ivChecked.visibility=View.GONE
        }else{
            holder.ivChecked.visibility=View.VISIBLE
        }
    }
}

class SearchContactViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    var ivChecked:ImageView=itemView.findViewById(R.id.iv_checked)
    var ivImg:BLImageView=itemView.findViewById(R.id.iv_img)
    var tvName:TextView=itemView.findViewById(R.id.tv_name)
}